<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp" %>
<html>
 <head>
    <title>销售解冻批次管理</title>
    <!-- import css and js -->
	<%@ include file="/common/meta.jsp" %>
	<%@ include file="/common/metaInput.jsp" %>  
	<script src="${ctx}/js/ligerUI/js/plugins/ligerLayout.js" type="text/javascript"></script>
	<script type="text/javascript" src="${ctx}/js/jsp/yd/logic/ItemStateData.js"></script>
	<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
	<script type="text/javascript">
		var basic_Url="${ctx}/yd/logic/sowareunfreeze";
		var ItemStateList = ItemStateData.Rows;
// 		alert("aaa:"+'${itemBatch}');
		var batch = '${itemBatch}';
		var grid;
		$(function(){
			var column1 =  [
				  { display: 'ID', name: 'id', width: 1 , hide:true},
                  { display: '产品id', name: 'materialsid', width: 1 , hide:true},//使用selecturl时必须设置该属性
                  { display: '<font color="gray">产品编码</font>', name: 'prodNo', width: 120},
				  { display: '<font color="gray">产品名称</font>', name: 'prodName', width: 120 },
				  { display: '<font color="gray">型号规格</font>', name: 'prodSpecDesc', width: 150 },
				  { display: '<font color="gray">基本单位</font>', name: 'prodBUnit', width: 80},
				  { display: '<font color="gray">产品批次</font>', name: 'prodBatch', width: 80},
				  { display: '<font color="gray">等级</font>', name: 'status', width: 80,
					  render: function (item){
	            		  var state=item.status;
	            		  if(state=="1"){
	            			  return "一等品";
	            		  }
	            		  if(state=="2"){
	            			  return "次品";
	            		  }
	            		  if(state=="3"){
	            			  return "旧件";
	            		  }
	            	  	}
				  },
				  { display: '<font color="gray">单位</font>', name: 'prodUnit', width: 70 },
				  { display: '<font color="gray">单位换算率</font>', name: 'prodUnitConvert', width: 70},
				  
				  {display : '<font color="gray">本次可解冻数量</font>',name : 'tmpCanFrozenQuantity',width : 100
						,render:function(item){
							item.tmpCanFrozenQuantity =
								(item.djQuantity==undefined?0:item.djQuantity) - (item.djckQuantity==undefined?0:item.djckQuantity) - (item.djjdQuantity==undefined?0:item.djjdQuantity);
							return item.tmpCanFrozenQuantity+"";
						  }
				  },
				  { display: '申请解冻数量<font color="red">*</font>', name: 'sqjdQuantity', width: 80, type: 'float'
                	  ,editor:{type: 'float'},
                	  render:function(item){
                   		 if(!isNaN(item.sqjdQuantity) && !isNaN(item.prodUnitConvert)){
                   			if(0==item.sqjdQuantity){
                       			item.sqjdQuantity = '0';
                       		}
                 	    	item.sqjdBQuantity = (item.sqjdQuantity*item.prodUnitConvert).toFixed(4) ;
                 	    }else{
                 	    	item.sqjdBQuantity=null;//清除值
                 	   	}
                   		
                   		
           				return item.sqjdQuantity;
                	  }
           		   },
           		  { display: '<font color="gray">申请解冻基本单位数量</font>', name: 'sqjdBQuantity', width: 130, type: 'float'},
           		  { display: '<font color="gray">处理单冻结基本单位数量</font>', name: 'djBQuantity', width: 1 , hide:true},
         		  { display: '<font color="gray">处理单冻结数量</font>', name: 'djQuantity', width: 100},
                
         		  { display: '<font color="gray">基本单位数量</font>', name: 'djckBQuantity', width: 1 , hide:true},
          		  { display: '<font color="gray">处理单冻结出库数量</font>', name: 'djckQuantity', width: 112},
                 
          		  { display: '<font color="gray">基本单位数量</font>', name: 'djjdBQuantity', width: 1 , hide:true},
         		  { display: '<font color="gray">处理单冻结解冻数量</font>', name: 'djjdQuantity', width: 112}];
			
			
			var column2 =  [
							  { display: 'ID', name: 'id', width: 1 , hide:true},
                  { display: '产品id', name: 'materialsid', width: 1 , hide:true},//使用selecturl时必须设置该属性
                  { display: '<font color="gray">产品编码</font>', name: 'prodNo', width: 120},
				  { display: '<font color="gray">产品名称</font>', name: 'prodName', width: 120 },
				  { display: '<font color="gray">型号规格</font>', name: 'prodSpecDesc', width: 150 },
				  { display: '<font color="gray">基本单位</font>', name: 'prodBUnit', width: 80},
				  { display: '<font color="gray">产品批次</font>', name: 'prodBatch', width: 80},
				  { display: '<font color="gray">等级</font>', name: 'status', width: 80,
					  render: function (item){
	            		  var state=item.status;
	            		  if(state=="1"){
	            			  return "一等品";
	            		  }
	            		  if(state=="2"){
	            			  return "次品";
	            		  }
	            		  if(state=="3"){
	            			  return "旧件";
	            		  }
	            	  	}
				  },
				  { display: '<font color="gray">单位</font>', name: 'prodUnit', width: 70 },
				  { display: '<font color="gray">单位换算率</font>', name: 'prodUnitConvert', width: 70},
				  
				  {display : '<font color="gray">本次可解冻数量</font>',name : 'tmpCanFrozenQuantity',width : 100
						,render:function(item){
							item.tmpCanFrozenQuantity =
								(item.djQuantity==undefined?0:item.djQuantity) - (item.djckQuantity==undefined?0:item.djckQuantity) - (item.djjdQuantity==undefined?0:item.djjdQuantity);
							return item.tmpCanFrozenQuantity+"";
						  }
				  },
				  { display: '申请解冻数量<font color="red">*</font>', name: 'sqjdQuantity', width: 80},
           		  { display: '<font color="gray">申请解冻基本单位数量</font>', name: 'sqjdBQuantity', width: 130, type: 'float'},
           		  { display: '<font color="gray">处理单冻结基本单位数量</font>', name: 'djBQuantity', width: 1 , hide:true},
         		  { display: '<font color="gray">处理单冻结数量</font>', name: 'djQuantity', width: 100},
                
         		  { display: '<font color="gray">基本单位数量</font>', name: 'djckBQuantity', width: 1 , hide:true},
          		  { display: '<font color="gray">处理单冻结出库数量</font>', name: 'djckQuantity', width: 112},
                 
          		  { display: '<font color="gray">基本单位数量</font>', name: 'djjdBQuantity', width: 1 , hide:true},
         		  { display: '<font color="gray">处理单冻结解冻数量</font>', name: 'djjdQuantity', width: 112}];
 if('${billstatus}' != "" && '${billstatus}' != "1"  && '${billstatus}' != "3"){
	 grid = $("#table1").ligerGrid({
	        columns: column2, 
	                      enabledEdit: true,
	                      usePager: true,pageSize:1000,pageSizeOptions:[1000],enabledSort:false, checkbox: true,
	                      url : basic_Url+"/itemlist.do?itembatch="+encodeURIComponent(batch)+"&updstatus="+"${updstatus}",
	                      width: "100%", height:"98%"
	                  });
 }else{
	 grid = $("#table1").ligerGrid({
	        columns: column1, 
	                      enabledEdit: true,
	                      usePager: true,pageSize:1000,pageSizeOptions:[1000],enabledSort:false, checkbox: true,
	                      url : basic_Url+"/itemlist.do?itembatch="+encodeURIComponent(batch)+"&updstatus="+"${updstatus}",
	                      width: "100%", height:"98%",
	                      toolbar: { items: [
	                                         { line: true },
	                                         { text: '删除', click: deleteRow, img: '${ctx}/js/ligerUI/skins/icons/delete.gif' }
	                                         ]
	                                         }
	                  });
 }
				
			$("#pageloading").hide();
		
		});
		
		function getSelected(){
			var rows = grid.getCheckedRows();
			 return rows;
		}
		
		function Close(){
			CloseDialog();
		}
		function deleteRow()
		{ if('${billstatus}' != "" && '${billstatus}' != "1" && '${billstatus}' != "3"){
			return false;
		}else{
			grid.deleteSelectedRow();
		}
		}
		var ba=true;
		var num = 0;
		var jnum = 0;
		function yz(){
			var data = grid.getData();
			if (data != null && data.length > 0) {
				jnum = 0;
				num = 0;
				for ( var j = 0; j < data.length; j++) {
	 				if (undefined == data[j].sqjdQuantity
							|| isNaN(data[j].sqjdQuantity)
							|| data[j].sqjdQuantity <= 0) {
						$.dialog.alert("第" + (j+1) + "行的“申请解冻数量”数据不合法");
						ba = false;
						return false;
					}
					
					if( data[j].tmpCanFrozenQuantity
							< data[j].sqjdQuantity){
						$.dialog.alert("您第" + (j+1) + "的申请解冻数量大于可冻结数量");
						ba = false;
						return false;
					}
					jnum += parseFloat(data[j].sqjdBQuantity);
	 				num  += parseFloat(data[j].sqjdQuantity);
	 			}
			}
				ba=true;
		}
	</script>
	
  </head>
 <body style="padding:10px">  
 <input type="hidden" id="batchItem" name="batchItem"/>
       <div id="layout1">
       <div id="layout1">
<!--           <div class="panelBar"> -->
<!-- 	            <ul class="toolBar"> -->
<!-- 		           <li><a class="add" onclick="insert()"><span>新增</span></a></li> -->
<!-- 		       		<li><a class="delete" onclick="deleteRow()"><span>删除</span></a></li> -->
<!--                </ul> -->
<!--           </div> -->
          <div id="pageHeader" class="pageHeader">
               <div class="searchBar" id="multipleSearchDialog">
	                <table class="table" width="100%" id="searchHeader" >  
                        <tbody id="newbody">
                        </tbody>
 	                </table>
<!--                     <div class="subBar"> -->
<!-- 			             <ul> -->
<!-- 				             <li><div class="buttonActive"><div class="buttonContent"><button type="submit" id="btnSearch" onclick="insert()">添加</button></div></div></li> -->
<!--  				             <li><a class="button" onclick="clearSearch()"><span>删除</span></a></li>  -->
<!-- 			             </ul> -->
<!-- 	                </div> -->
               </div>
          </div>
      </div>
      <div position="center" id="table1">
      </div>
      <div class="clear"></div>
   </div>
    </body>
</html>